﻿/*******************************************************
 *  帮扶管理 相关操作js
 * <p>Title: banePovertyManager.js</p>
 * <p>Description:TODO</p>
 * @author Joychen
 * @date 2017年12月22日 下午5:41:57
 * @version 1.0
 * *****************************************************/
//帮扶管理
var unitzTree, selNode, $table, addOrEditUrl, orgId = null, isParent = false, folder_path,issetOut=false;
var addIndex, options;
var banePovertyManager = {
    //初始化页面
    initPage: function () {
        parent.showLoadBoxs();
        banePovertyManager.bindZtree();
        banePovertyManager.initTable();
        banePovertyManager.bindEvent();
        parent.delLoadBoxs();
    },
    bindZtree: function () {
        var setting = {
            view: {
                showIcon: true,
                selectedMulti: false,
                fontCss: getFontCss
            },
            edit: {
                enable: true,
                showRemoveBtn: false,
                showRenameBtn: false
            },
            async: {
                enable: true,
                dataType: "text",
                type: "post",
                url: ctx + '/SysOrg/GetOrgTreeDataByRelation',
                autoParam: ["id"]
            },
            data: {
                key: { title: "name", name: "name" },
                simpleData: { enable: true, idKey: "id", pIdKey: "pId", rootPId: 0 }
            },
            check: {
                enable: false,
                autoCheckTrigger: true,
                chkStyle: "checkbox",
                chkboxType: { "Y": "p", "N": "ps" }
            },
            callback: {
                onAsyncError: function () {
                    layer.msg("初始化单位结构树失败~", { icon: 5 });
                },
                onAsyncSuccess: function (event, treeId, treeNode, msg) {
                    //树加载完成后执行
                    var obj = unitzTree.getNodes()[0];
                    if (obj) {
                        issetOut = true;
                        unitzTree.selectNode(obj);
                        unitzTree.setting.callback.onClick(null, unitzTree.setting.treeId, obj);//模拟点击事件 
                        if (obj.children && obj.children.length > 0)
                            unitzTree.expandNode(obj);
                    }
                },
                onClick: function (event, treeId, treeNode) {
                    $('#unitTree a').css("color", "#333");
                    $('#' + treeNode.tId + '_a').css("color", "#ffffff");
                    isParent = treeNode.isParent;
                    orgId = treeNode.id;
                    selNode = treeNode;//选中节点
                    folder_path = treeNode.folder_path;
                    if (issetOut)
                    { setTimeout(function () { $table.bootstrapTable('refresh'); issetOut = false; }, 1000); }
                    else
                        $table.bootstrapTable('refresh');
                }
            }
        };
        unitzTree = $("#unitTree").initzTreeView(setting, 'ushow');
    },
    //初始化Table
    initTable: function () {
        options = {
            url: ctx + "/BaneJobIssue/GetBanePovertyUserData",
            cutHeight: 5,
            toolbar: "#exampleToolbar",
            queryParams: function (params) {
                params = {
                    rows: params.limit,
                    //页面大小  
                    page: params.offset / params.limit + 1,
                    orgId: orgId,//选中单位(组织机构)
                    folder_path: folder_path,
                    isParent:isParent?1:0,
                    baneName: encodeURI($('#baneName').val()) //人员姓名
                }
                return params;
            },
            columns: [
            {
                radio: true
            },
	        {
	            field: '',//第一列序号
	            title: '序号',
	            align: 'center',
	            width: 50,
	            formatter: function (value, row, index) {
	                return index + 1;
	            }
	        },
	        {
	            field: 'user_name',
	            title: '用户名',
	            align: 'center'
	        },
	        {
	            field: 'user_identify',
	            title: '身份证',
	            align: 'center'
	        },
	        {
	            field: 'jobNum',
	            title: '就业情况统计',
	            align: 'center',
	            formatter: function (value, row, index) {
	                return "<button class='btn btn-danger btn-circle btn-outline' onclick=banePovertyManager.openForm('job','" + row.user_name + "'," + row.user_id + ",'" + row.user_identify + "')>" + value + "</button>";
	            }
	        }, {
	            field: "trainNum",
	            title: '帮扶培训统计',
	            align: 'center',
	            formatter: function (value, row, index) {
	                return "<button class='btn btn-danger btn-circle btn-outline' onclick=banePovertyManager.openForm('train','" + row.user_name + "'," + row.user_id + ",'" + row.user_identify + "')>" + value + "</button>";
	            }
	        }, {
	            field: 'evalNum',
	            title: '评估报告统计',
	            align: 'center',
	            formatter: function (value, row, index) {
	                return "<button class='btn btn-danger btn-circle btn-outline' onclick=banePovertyManager.openForm('eval','" + row.user_name + "'," + row.user_id + ",'" + row.user_identify + "')>" + value + "</button>";
	            }
	        }]
        }
        $table = tableHelper.initTable("exampleTableToolbar", options);
    },
    //绑定默认事件
    bindEvent: function () {
        //查询
        $('#btnSearch').click(function () {
            $table.bootstrapTable('refresh', options);
        });
    },
    //打开页面
    openForm: function (type, user_name, user_id, user_identify) {
        var $title = "", $url = "";
        var urlIndex = "?user_id=" + user_id + "&user_name=" + encodeURI(user_name) + "&user_identify=" + user_identify;
        //user_id,user_name
        switch (type) {
            //就业
            case "job": { $title = user_name + "：就业帮扶情况"; $url = ctx + "/BaneJobIssue/SingleHelpJobList" + urlIndex; } break;
            //培训
            case "train": { $title = user_name + "：帮扶培训情况"; $url = ctx + "/BaneJobIssue/SingleHelpTrainList" + urlIndex; } break;
            //报告
            case "eval": { $title = user_name + "：评估报告"; $url = ctx + "/BaneJobIssue/SingleHelpEvalList" + urlIndex; } break;
        }
        layer.open({
            id: 'singleiFrameHelp',
            title: [$title, 'font-size:18px;'],
            type: 2,
            content: $url,
            scroll: true,//是否显示滚动条、默认不显示
            btn: '',
            area: ['1200px', '98%'],
            cancel: function (li, o) {
                var isFrish = document.getElementById("singleiFrameHelp").firstChild.contentWindow.isFrish;
                if(isFrish)
                    $table.bootstrapTable('refresh', options);
            }
        });
    }
}


